Part Number Hot Search : 
12A01 PIC18 PJ48A SP712007 7552BS 54735 IFN425 SWL623
Product Description
Full Text Search
 

To Download AN413 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? application note initialization of the st9 introduction the st9 family offers the microprocessor designer a wide variety of architectural features configurable to the user's specific application requirements. central to all these configurations is a multiple register based microcomputer core to which may be added on-chip, powerful peripheral components including a/d convertors, serial communication interface units (sci's), and 16-bit multifunction timers with input capture/output compare capabilities. the availability, on-chip, of these application-specific units obviates the need for external interface design as well as offeringhigh-speed and good reliability. the particular peripherals incorporated on-chip may themselves be individually configured to offer a wide variety of functional (architectural) alternatives. this configuration is typically implemented by simple software routines included in the power-on- or system- reset routines. the sole difficulty which the user may initially encounter stems, in fact, from the power and versatility of this approach to system design. the large number of available options means that the user must specify a large number of system parameters by initializing control register contents for the specific peripheral units. the objective of this application note is to suggest to the user a programming structure andphilosophy to aid in the initial configuration of the system. the approach is illustrated by a number of specific examples selected from the wide range available for the st9030, st9040 families, but are applicable to all st9s. system reset after processor reset the control and status registers, located on the group f pages (0-63) are forced to preset values which define a default reset configuration for the st9 system. by way of example the internal clock frequency (intclk) is set to the internal crystal oscillator (or externally applied clock frequency, if supplied) divided by two without prescaling, and the individual pins of parallel ports 0,1, and 6 are set to bidirectional pullup mode (for systems with on-chip rom). on releasing the external reset signal the processor pc is loaded with the contents of the reset vector stored in address locations 0 and 1. this causes a jump to a reset routine in which the designer may reconfigure the st9 system as appropriate to the requirements of his particular application, by loading suitable values into the system registers. the number of registers to be initialized may be considerable for a representative st9 system. additionally, the application-specific interrupt routines will, in general, involve the m anipulation of substantial system resources, e.g. read/write of data registers, and test/reset of status, mask, and control registers. the associated programming task may appear daunting in prospect on firstacquaintancewith the st9 system. conceptually, the organization of the associated software is relatively simple and straightforward as may be recognized by grouping under four headings the programming steps involved in the initialization of st9 peripherals and the organization of interrupt service routines. pierre guillemin and alan dunworth AN413 / 1292 1/44
a) st9 core system configuration certain core system resources are common to all on-chip peripherals and may be specified in a common routine which is invoked at system reset. such common resources include clock configuration, system and user stack specification, global interrupt masking, processor priority setting, parallel port bit-by-bit specification, and setting of external memory wait-cycles. the setting up of the interrupt vector table, and certain global masking or enabling operations, may also be included under this heading. b) individual on-chip peripheral configuration the configuration of on-chip peripherals, e.g. multifunction timers, a/d converters, etc., involves the loading of suitable bit-patterns into group f page registers. this enables the specification of input and output signals, determination of the peripheral's mode of operation, and the selection of internal or external clock and control signals. c) individual on-chip peripheral initialization the initialization of a particular on-chip peripheral may involve the setting or clearing of device-specific enable and masking bits, specification of interrupt priority levels, clearing of status/flag values, and the loading of data and/or limit registers. d) organization of interrupt service routines this will normally include context-saving and restoring of the pc and system status, plus the working-reg- ister and page-pointer registers, together with the values of any working registers used in the routine. the routine proper may include testingof status flag bits, and the reading and writing of data registers associated with the particular device. finally, the interrupt pending bits should be cleared, the context restored, and individual masking and enabling bits restored to the appropriate values. in practical programming terms there will normally be a single routine invoked on system reset which carries out the core system configurations listed under heading a) above. for each individual peripheral there will typically be a single routine which carries out the configuration andinitialization operations listed under headingsb) and c). there will also be one or more interrupt routines associated with each peripheral, e.g. the a/d converter may require in general two interrupt routines, one for end of conversion, and one for out of range operation (i.e. analog watchdog operation) on channels 6 and 7. an example of a core-system configuration is given in appendix b, and appendices c,d,e, and f give configuration/initialization examples, and interrupt routines for the timer, a/d convertor, sci unit, and timer/watchdog respectively. there is not space in a short note to discuss these programmes in detail on a line by line basis. instead the approach will be to list, for each device, the resources which need to be taken into consideration when configuring, initializing, and servicing the particular device. an example will then be given of the specific use of each such resource. with this background, the interested user should be able to follow in detail those listings most relevant to his particular application area. ? initialization of the st9 2/44
st9 basic system configuration tables a.1 and a.2 in appendix a lists the registers which should be loaded with specified bit-patterns in order to initialize the st9 to a basic system configuration. a demonstration routine which carries this out for a representative st9 system is listed in appendix b. the main routine, reset_start, is invoked at system reset. also shown in appendix b are the assembler declarations and directives which enable the interrupt vector address table to be set up in program memory. the vector address table the st9 implements an interrupt vectoring structure that allows the on-chip peripheral to identify the location of the first instruction of the interrupt service routine (isr). each interrupt module has a specific interrupt vector register (ivr) mapped on the register file pages. when the interrupt request is acknow- ledged, the peripheral interrupt module provides, via the ivr, the vector to point to the address of the interrupt service routine in the vector table. the interrupt vector table containing the list of addresses of the interrupt service routine must be located in the first 256 locations of program memory. the first 6 locations of program memory are reserved as follows: note that since the above locations are fixed by the hardware no associated ivr register is involved. for certain interrupt modules more than one interrupt routine may be required. for example the a/d convertor has separate interrupts for the end of conversion and channel 6/7 analog underflow/overflowconditions. in such cases the ivr register specifies the more significant, and the interrupt module hardware specifies the less significant bits of the vector table address. the following assembler outline shows how the corresponding vector table entries may be established. adc_it_vect:= 30h . .org adc_it_vect .word adc_wdg .word adc_eoc . adc_wdg: ; code for the analog watchdog routine is included here ; note that in the example in appendix b ; the system reset routine is invoked for out of ; range conditions on channels 6 and 7 . iret adc_eoc: ; end of a/d conversion interrupt routine included here iret address content 0 address high of power on reset routine 1 address low of power on reset routine 2 address high of divide by zero trap subroutine 3 address low of divide by zero trap subroutine 4 address high of top level isr 5 address low of top level isr ? initialization of the st9 3/44
port initialization the st9 has up to a maximum of 64 lines dedicated to input/output. these lines, grouped into eight 8-bit ports, can be independently programmed to provide parallel input/outputs with or without handshake or may be used to connect in/out signals to/from the peripherals (e.g. core, timers, sci units, etc.) present on the chip. the functional allocation of the ports to support system tasks may be summarised as follows: port functions 0 usable as i/o port (without handshake) or as multiplexed low-address and data lines for external memory. 1 usable as i/o port (without handshake)or as high-address lines for external memory. 2 usable as i/o port (without handshake)or for spi functions; also int1, int2, and int3 inputs. 3 usable as i/o port (without handshake)or for timer functions. 4 usable as i/o port (with or without handshake) 5 usable as i/o port (with or without handshake). 6 usable as i/o port (without handshake) 7 usable as i/o port (without handshake) or for sci functions. also used for int4, int5, and int6 inputs or for control signals for slow external memory ports 0, 1, and 6 are automatically initialized on system reset to correspond to the installed on-chip memory. ports 2, 3, 4, 5, 6, and 7 need to be initialized (if available) to satisfy the specific application requirements for external i/o, plus any alternative function assignments of port pins, and internal interconnections. table a.3, appendix a, lists the complete set of port configuration registers together with their addresses. example: c7 0a spp p3c_pg f5 fc 05 ld p3c0r,#00000101b f5 fd 0f ld p3c1r,#00001111b f5 fe 05 ld p3c2r,#00000101b in this example port 3 pins 4, 5, 6, and 7 are configured as bidirectional pins, with weak pull-up output and ttl inputs. pins 0 (t0ina) and 2 (t0inb) are configured as ttl inputs, and pins 1 (t0outa) and 3 (t0outb) are configured as alternate function push-pull outputs. ? initialization of the st9 4/44
multifunction timer configuration the st9 multifunction timer is configured by loading suitable control-bit patterns in the groupe f page register tcr, tmr, icr, oacr, and obcr (see table a.4 in appendix a). note that registers eimr and cicr provide global control functions common to all on-chip peripherals and are hence initialized conveniently in the basic system configuration routine. the external input control register, icr , controls input source selection (internal/external), input mode selection (falling/rising edge sensitive, etc.), counter mode of operation (continuous, one-shot, etc.), and input function (gate, trigger, up/down control, etc.). example: f5 fa 54 ld t_icr,#01010100b this instruction selects the external input a as a falling-edge-sensitive trigger input, and the b input is a normal port i/o pin. the multifunction timer control register, tcr , controls counter clear and prescaler reload operations as well as providing a counter enable control bit and counter status flags. example: f5 f8 48 ld t_tcr,#01001000b this instruction halts the counter operation but provides for subsequent up counting with counter clear and prescaler reload on reg0 or reg1 capture. the multifunction timer mode register, tmr , selects the clock source for the counter-prescaler input, enables retrigger or continuous mode, and controls register load/capture operations. example: 98 8c ld t_tmr,#10001100b this pattern enables output 1 and disables output 0, disables bivalue modes, and selects reg0 for capture and reg1 for monitor. retriggerable continuous mode is selected. the output control register, oacr, links the output t0outa to counter overflow/underflow and compare events, and provides for subsequent set, reset, or toggle of the external output. the on-chip event (oce) may be linked to a comp0 event. example: f5 f5 1b ld t_oacr,#00011011b in this example t0outa is preset to 1, and issubsequently set by comp0, toggled by comp1, and reset by ovf. the oce signal is generated by a successful cmp0 compare event. the output control register, obcr , links the output t0outb to counter overflow/underflow and compare events, and provides for subsequent set, reset, or toggle of the external output. the on-chip event (oce) may be linked to a counter overflow/underflow event. example: f5 f6 83 ld t_obcr,#10000011b in this example t0outb is preset to 1, and is subsequentlyreset by comp0, and set by ovf and comp1. the oce signal is generated by a counter overflow/underflow event. ? initialization of the st9 5/44
multifunction timer initialization initialization of the multifunction timer requires loading of the prescaler register and the two comparison registers. the timer status register should be cleared, the vector table entry should be set, and the multifunction timer counter actions enabled. the interrupt/dma priority levels should be set and the mask bits should be adjusted as appropriate to the application. further, if dma operations are specified, dma address and counter registers will require initialization. the prescaler register, prsr, holds the preset value for the 8-bit prescaler. example: bc 00 ld t_prsr,#00h this defines a division ratio of 1 and the maximum counter clock is generated (intclk/3). the multifunction timer flags register, flagr , contains flags which register successful capture or comparison events together with ovf/unf and overrun conditions. example: 15 fe fd and t_flagr,#~ocm0 this example resets the overrun bit for comp0 operations. the interrupt vector register, ivr, should be loaded with the 5 most significant bits of the multifunction timer's interrupt vector address in program memory. the interrupt source (compare, capture, or ovf/unf) provides the least significant 3 bits to provide the correct vector link. example: f5 f2 10 ld t0_ivr,#t0_it_vect in this example ivr is loaded with the start address (10h) of the block of 8 words in the vector table allocated to the 5 different multifunction timer interrupts. ? initialization of the st9 6/44
multifunction timer initialization (continued) the i nterrupt/dma control register, idcr, is used to set the interrupt and dma priority levels, and the dma transfer source and destination. it also enables swap mode and contains end of block condition flags. example: f5 f3 d6 ld t0_idcr,#11000110b in this example the priority level is set at a value of 6, and the swap mode is disabled. the dma capture channel source is reg0, and the dma compare channel source is cmp0. the interrupt/dma mask register, idmr, contains a global multifunction timer interrupt enable plus individual dmaand interrupt enable bits for overflow as well as successful capture and comparison events. example: f5 ff 04 ld t_idmr,#00000100b 0f ff 80 or t_idmr,#gtien the first instruction sets the interrupt enable on cmp0, and the second instruction globally enables all multifunction timer interrupts. the dma counter pointer register, dcpr, defines the dma area and source, and specifies the location of the dma length register. example: f5 f0 4c ld t0_dcpr,#cpt_lg_dma the dma length register is 4ch = rr12 = rr76 and the transfer occurs to/from program/data memory. the dma address pointer register, dapr , defines the dma area and source, and specifies the location of the dma address register. example: f5 f1 48 ld t0_dapr,#cpt_ad_dma the dma address register is 48h = rr8 = rr72. in conjunction with the dpcr value in the above example it specifies program memory for the buffer. ? initialization of the st9 7/44
a/d convertor configuration/initialization configuration of the a/d convertor requires loading of 4 registers only, clr, crr, icr, and ivr (table a.6), and initialization of this device involves, apart from global masking, loading of two double (t hreshold registers). hence a single routine can be written to cover both the configuration and initialization aspects of a/d convertor use. the control logic register, clr , defines the analog channel conversion start address, selects inter- nal/external triggers, and enables continuous or single conversion and power up/down modes. this register also contains a start/stop status/control bit. example: f5 fd 04 ld ad_clr,#00000100b in this example, the conversion scan starts with channel 0 when enabled, powers up the a/d convertor, halts conversion, and specifies single conversion scan mode. please note that before enabling any a/d conversion, it is mandatory to set the low bit of control logic register at least 60 m s before the first conversion start. this is in order to correctly bias the analog section of the converter. the interrupt vector register, ivr , defines the most significant 6 bits of the vector table byte address. it thus points to the first of two word addresses which correspond to the analog watchdog and end of conversion interrupt routines. example: f5 ff 32 ld ad_ivr,#adc_iteoc_vect in this example, an address of 50 (decimal) is loaded into ivr. hence a subsequent a/d convertor eoc interrupt will cause a vector table access at location 50. the interrupt control register, icr , contains the priority level specification, the two source interrupt flags (analog watchdog and eoc) and their individual masking bits. example: f5 fe 20 ld ad_icr,#00100000b 05 fe 20 or ad_icr,#00000110b in this example, the priority level is first set at 0, end of conversion interrupts are enabled, and theanalog watchdog interrupt is masked. the second instruction then sets the priority to a level of 6. if the analog watchdog is enabled (bit 6 in icr) it will be necessary to load the threshold registers for channels 6 and 7. in this case access will be made in the interrupt routine to register crr. the compare result register, crr, contains 4 flags showing the results of comparison operations between the current values of data registers 6 and 7, and the upper and lower threshold registers. ? initialization of the st9 8/44
sci unit configuration the list of registers to be initialized when configuring the sci unit is given in table a.9. the functions of these registers, and some illustrative examples of their use, are as follows: the character configuration register, chcr , is used to define the serial frame format. example: ac e3 ld s_chcr,#e3h this example defines a serial frame as follows: 8 data bits, 1 stop bit, even parity, and address input if the character matches the contents of the address register. the clock configuration register, clcr , is used to specify the transmitter, receiver, and baud rate clock sources, and the clock divisor ratio. it also enables auto echo and loopback test modes. example: bc 80 ld s_clcr,#txclk in this example, the transmitter and receiver clocks are provided by the baud rate generator. each data bit period will be 16 clock periods (asynchronous mode), and the auto loop and loopback modes are disabled. the baud rate generator register, brgr, specifies a 16-bit division ratio. example: bf dc 00 4e ldw s_brgr,#div_9600 this example specifies a division ratio yielding 9600 bauds with a 24 mhz external clock. writing to a baud rate generator register immediately disables and resets both the sci baud rate generator, the transmitter and receiver circuitry. after writing to the remaining baud rate generator register, the transmitter and receiver circuits are enabled. the baud rate generator will load the new value and start counting. to initialize the sci, user should first initialize one baud rate generator divisor register. this will reset all sci circuitry. initialize all other sci registers for the desired operating mode. to enable the sci, initialize the remaining baud rate generator register. the address compare register, acr, contains an 8-bit value which may be used as a match against which a received address may be tested to set the receive address pending bit. example: 5c 0d ld s_acr,#return this will cause the receive address pending bit to be set if an end of command character bit-pattern is received. ? initialization of the st9 9/44
sci unit configuration (continued) the interrupt vector register, ivr , defines the most significant 5 bits of the vector table byte address. it thus points to the first of four vector table word address entries. example: 4c 00x ld s_ivr,#sci_it in this example, after the external symbol has been linked in, the vector table entry address will beloaded into ivr at execution time. the interrupt mask register, imr, contains five interrupt masking bits and two end of block dma status bits. it also selects the shift register or holding register as source of the transmitter register empty interrupt. example: 6c 05 ld s_imr,#00000101b in this example the interrupt pending bits are reset, the transmitter data interrupt is masked, and the receiver data, data error, and address interrupts are unmasked. the interrupt/dma priority register, idpr, specifies the interrupt/dma priority, selects one of four address modes, and controls the emission of break characters and enables address/9th bit data mode. it also provides mask bits for receive and transmit dma transfers. example: 9c 04 ld s_idpr,#04h in this example a priority level of 4 is specified, and transmitter dma requests are masked. ? initialization of the st9 10/44
sci unit initialization the list of registers to be initialized when initializing the sci unit is given in table a.10. the functions of these registers, and some illustrative examples of their use, are as follows: the receiver dma transaction counter pointer register, rdcpr , contains the register file address of the receiver dma transaction counter. in addition it determines whether the dma transfers occur in the register file or in memory. example: an example of the use of this register is provided below (see rdapr example). the receiver dma destination address pointer register, rdapr , contains the register file address of the receiver dma data destination. in addition, in conjunction with bit 0 of rdcpr, it determines whether the dma transfers occur in program or data memory. example: 00 ff lng-dma_sci := 0fh 00 a0 depart_dma_sci := 0a0h 00 02 num_rdap := 2 00 03 num_rdcp := 3 2c 03 ld s_rdcpr,#num_rdcp 1c 02 ld s_rdapr,#num_rdap f5 03 0f ld r#num_rdcp,#(lng_dma_sci) f5 02 00 ld r#num_rdap,#(depart_dma_sci) in this program sequence the dma transaction counter and address pointer register addresses are defined to be r3 and r2 respectively. these two registers are initialized for a block of size 15 bytes starting at register address a0, i.e. r160. the transmitter dma transaction counter pointer register, tdcpr , contains the register file address of the transmitter dma transaction counter. in addition it determines whether the dma transfers occur in the register file or in memory. example: an example of the use of this register is provided below (see tdapr example). the transmitter dma destination address pointer register, tdapr , contains the register file address of the transmitter dma data destination. in addition, in conjunction with bit 0 of tdcpr, it determines whether the dma transfers occur in program or data memory. example: 00 ff lng-dma_sci := 0fh 00 a0 depart_dma_sci := 0a0h 00 06 num_tdap := 6 00 07 num_tdcp := 7 2c 07 ld s_tdcpr,#num_tdcp 3c 06 ld s_tdapr,#num_tdap f5 07 0f ld r#num_tdcp,#(lng_dma_sci) f5 06 00 ld r#num_tdap,#(depart_dma_sci) in this program sequence the dma transaction counter and address pointer register addresses are defined to be r7 and r6 respectively. these two registers are initialized for a block of size 15 bytes starting at register address a0, i.e. r160. ? initialization of the st9 11/44
timer/watchdog unit configuration configuration of the timer/watchdog requires loading of the 6 registers listed in table a.11, appendix a. timer/watchdog unit configuration the timer/watchdog control register , wdtcr , containsa start/stop bit, and is also used to select input, output, and counter modes, as well as input and outputenable bits. example: bc 80 ld wdtcr,#80h in this example the timer starts counting down in continuous mode, and the input and output sections are disabled. the wait control register , wcr , as well as specifying the number of wait states for access to off-chip program and data memory enables the watchdog function. example: cc 40 ld wcr,#wden in this example the watchdog action is disabled, and the number of wait states are set to zero. the external interrupt vector register , eivr , contains a bit, tlis, which is used to control the top level interrupt source (timer/watchdog eoc or external nmi). a second bit iaos is used to select the timer/watchdog as an interrupt source on channel a0 (int0). this register is also used to supply the 4 most significant bits of the external interrupt vector. example: 6c 20 ld eivr,#ext_it_vect in this example the timer/watchdog eoc generates an interrupt on channel a0 at each end of count. the top level interrupt is isolated from the nmi input and may be used for a software trap. the timer/watchdog prescaler register, wdtpr, contains an 8-bit value which is loaded into the prescaler register. example: 90 da clr wdtpr the specified prescaler value of zero leads to a minimum timer count period of 333ns, assuming a system clock running at 12mhz. the timer/watchdog high register, wdthr , and timer/watchdog low register, wdtlr, together contain a 16-bit value which is loaded into the counter at each end of count. example: bf f8 0b bb ldw wdtr,#3003 the specified count value leads to a count period of about 1 millisecond, (3003 x 333ns). ? initialization of the st9 12/44
timer/watchdog unit initialization the external interrupt priority level register , eiplr , specifies the priority level of four pairs of external interrupts, a), a1,...d0, d1. it is thus used to set the priority of the timer/watchdog eoc interrupt routine, called via channel a0. example: 5c fe ld eiplr,#0feh in this example priority levels of 4 and 5 are specified for the pair inta0, inta1. the external interrupts pendingbit register , eipr , holds the eight interruptpending bits for the external interrupts, including, in the present context, the watchdog/timer eoc interrupt. these bits are set by hardware action and reset by software during the service routine. example: 90 d3 clr eipr in this example all the external interrupt pending bits are cleared. the external interrupts mask-bit register, eimr, holds the eight interrupt mask bits for the external interrupts, including, in the present context, the timer/watchdog eoc interrupt. example: 4c 01 ld eimr,#ia0 in this example the timer/watchdog end of count on channel a0 is unmasked. ? initialization of the st9 13/44
interrupt service routine organization when an enabled interrupt is acknowledged the interrupt machine cycle performs the following actions: (i) all maskable interrupts are disabled by clearing the ei bit of register cicr. (ii) the pc (two bytes) and the flags register are saved on the system stack. (iii) the pc is loaded with the 16-bit vector stored in the vector table. on exit from the interrupt service, using an iret instruction the following operations are carried out: (iv) the flagr register is restored from the system stack. (v) the pc is restored from the system stack. (vi) the unmasked interrupts are enabled by setting the cicr.ei bit. in general additional resources must be saved and restored apart from thosehandled automatically by the system as listed above. in a typical case these additional resources will include the two register pointer registers, the page-pointer register, and any working registers used in the interrupt routine. an outline for a suitable interrupt service routine is hence as follows: label_int: work_reg_page0 = (0dh*2) work_reg_page1 = (0dh*2) + 1 wdt_pg = 0 t0c_pg = 9 t0d_pg = 10 s_pg = 24 ad0_pg = 63 push rp0 push rp1 push ppr spp #t0d_pg srp0 #work_reg_page0 srp1 #work_reg_page1 push r0 push r1 push ra ; ; ;interrupt service routine ;appears here, including ;read/write data registers ;test status flags ;clear interrupt pending flags pop ra pop r1 pop r0 pop ppr pop rp1 pop rp0 iret ? initialization of the st9 14/44
summary this application note has attempted to formalize and simplify the programming task of configuring and initializing an st9 system. the resources to be controlled have been listed with brief examples of their use. complete examples of st9 configuration, initialization, and interrupt service routines are presented in a set of appendices. these programs have been written for an st9030 but can be readily adapted where necessary for use with other versions. references (1) ast9 technical manualo, sgs-thomson microelectronics. (2) application note an411, symbols.inc standard definitions of st9 registers and register-bits. appendices a. st9 core and peripheral configuration/initialization registers. a.1. system configuration: system registers. a.2. system configuration: paged registers. a.3. port configuration registers. a.4. multifunction timer configuration/initialization registers. a.5. multifunction timer data/status register. a.6. a/d configuration/initialization registers. a.7. a/d channel registers. a.8. a/d threshold registers a.9. sci configuration registers. a.10. sci initialization registers. a.11. watchdog timer configuration/initialization registers. a.12. spi init ialization. a.13. eeprom initialization. b. examples of st9 system configurations. c. examples of multifunction timer 0 configurations. d. examples of a/d converter configurations. e. examples of sci configurations. f. examples of timer/watchdog configurations. ? initialization of the st9 15/44
mnem. name reg. hex pg. reset value (hex) cicr central interrupt control register r230 e6 - 87 flagr flags register r231 e7 - xx rp0r register pointer 0 r232 e8 - xx rp1r register pointer 1 r233 e9 - xx ppr page pointer register r234 ea - xx moder mode register r235 eb - e0 usphr user stack pointer (high) r236 ec - xx usplr user stack pointer (low) r237 ed - xx ssphr system stack pointer (high) r238 ee - xx ssplr system stack pointer (low) r239 ef - xx a.1. system configuration: system registers mnem. name reg. hex pg. reset value (hex) eecr eeprom control register mask register r241 f1 0 87 eitr external interrupt trigger-event register r242 f2 0 xx eipr external interrupt pending register r243 f3 0 xx eimr external interrupt mask register r244 f4 0 xx eiplr external interrupt priority level register r245 f5 0 xx eivr external interrupt vector register r246 f6 0 e0 nicr nested interrupt control register r247 f7 0 xx wcr wait control register r252 fc 0 7f a.2. system configuration: page registers appendix a. st9 core and peripheral configuration/initialization ? initialization of the st9 16/44
port name registers hex pg. (hex) 0 data register control registers (pxc0-pxc2) r224 r240-r242 e0 f0-f2 - 2 1 data register control registers (pxc0-pxc2) r225 r244-r246 e1 f4-f6 - 2 2 data register control registers (pxc0-pxc2) handshake control register r226 r248-r250 r251 e2 f8-fa fb - 2 2 3 data register control registers (pxc0-pxc2) handshake control register r227 r252-r254 r255 e3 fc-fe ff - 2 2 4 data register control registers (pxc0-pxc2) handshake control register r228 r240-r242 r243 e4 f0-f2 f3 - 3 3 5 data register control registers (pxc0-pxc2) handshake control register r229 r244-r246 r247 e5 f4-f6 f7 - 3 3 6 data register control registers (pxc0-pxc2) r251 r248-r250 fb f8-fa 3 3 7 data register control registers (pxc0-pxc2) r255 r252-r254 ff fc-fe 3 3 reset values: ports 2, 3, 4, and 5: pcx0: 00000000 pcx1: 00000000 pcx2: 00000000 handshake control registers: 111111111 a.3. port configuration registers ? initialization of the st9 17/44
mnem. name reg. hex pg. reset value (binary) cicr central interrupt control register r230 e6 - 10000111 tcr timer control register r248 f8 10 00000xxx tmr timer mode register r249 f9 10 00000000 icr external interrupt control register r250 fa 10 0000xxxx oacr output a control register 0 r252 fc 10 xxxxxx0x obcr output a control register 1 r253 fd 10 xxxxxx0x idmr interrupt/dma mask register r255 ff 10 00000000 dcpr dma counter pointer register r240 f0 9 xxxxxxxx dapr dma address pointer register r241 f1 9 xxxxxxxx ivr interrupt vector register r242 f2 9 xxxxxxxx idcr interrupt/dma control register r243 f3 9 11000111 a.4. multi-function timer configuration/initialization registers (mft0) mnem. name reg. hex pg. reset value (binary) reg0hr capture/reload register 0 (high) r240 f0 10 xxxxxxxx reg0lr capture/reload register 0 (low) r241 f1 10 xxxxxxxx reg1hr capture/reload register 1 (high) r242 f2 10 xxxxxxxx reg1lr capture/reload register 1 (low) r243 f3 10 xxxxxxxx cmp0hr compare register register 0 (high) r244 f4 10 xxxxxxxx cmp0lr compare register register 0 (low) r245 f5 10 xxxxxxxx cmp1hr compare register register 1 (high) r246 f6 10 xxxxxxxx cmp1lr compare register register 1 (low) r247 f7 10 xxxxxxxx prsr prescaler register r251 fb 10 00000000 flagr timer flags register r254 fe 10 00000000 a.5. timer data/status registers (mft0) ? initialization of the st9 18/44
mnem. name reg. hex pg. reset value (binary) crr compare result register r252 fc 63 00001111 clr control logic register r253 fd 63 00000000 icr interrupt control register r254 fe 63 00001111 ivr interrupt vector register r255 ff 63 xxxxxx10 a.6. a/d configuration/initialization registers mnem. name reg. hex pg. ad_d0r channel 0 data register r240 f0 63 ad_d1r channel 1 data register r241 f1 63 ad_d2r channel 2 data register r242 f2 63 ad_d3r channel 3 data register r243 f3 63 ad_d4r channel 4 data register r244 f4 63 ad_d5r channel 5 data register r245 f5 63 ad_d6r channel 6 data register r246 f6 63 ad_d7r channel 7 data register r247 f7 63 a.7. a/d channel registers mnem. name reg. hex pg. ad_lt6r channel 6 lower threshold register r248 f8 63 ad_ut6r channel 6 upper threshold register r249 f9 63 ad_lt7r channel 7 lower threshold register r250 fa 63 ad_ut7r channel 7 upper threshold register r251 fb 63 a.8. a/d threshold registers ? initialization of the st9 19/44
mnem. name reg. hex pg. reset value (binary) ivr interrupt vector register r244 f4 24 xxxxxxxx imr interrupt mask register r246 f6 24 0xx00000 isr interrupt status register r247 f7 24 xxxxxxxx idpr interrupt/dma priority register r249 f9 24 xxxxxxxx chcr character recognition register r250 fa 24 xxxxxxxx ccr clock configuration register r251 fb 24 00000000 brghr baud rate generator divisor register (high) r252 fc 24 xxxxxxxx brglr baud rate generator divisor register (low) r253 fd 24 xxxxxxxx a.9. sci configuration registers mnem. name reg. hex pg. reset value rdcpr receiver dma transaction counter register r240 f0 24 xxxxxxxx rdapr receiver dma address pointer register r241 f1 24 xxxxxxxx tdcpr transmit dma transaction counter register r242 f2 24 xxxxxxxx tdapr transmit dma address pointer register r243 f3 24 xxxxxxxx acr address compare register r245 f5 24 xxxxxxxx rxbr receive buffer register (read only) r248 f8 24 xxxxxxxx txbr transmitter buffer register (write only) r248 f8 24 xxxxxxxx a.10. sci initialization ? initialization of the st9 20/44
mnem. name reg. hex pg. reset value (binary) eipr external interrupt pending register r243 f3 0 00000000 eimr external interrupt masking register r244 f4 0 00000000 eiplr external interrupt priority register r245 f5 0 111 11111 eivr external interrupt vector register r246 f6 0 xxxx0010 wdtlr watchdog timer low register r248 f8 0 xxxxxxxx wdthr watchdog timer high register r249 f9 0 xxxxxxxx wdtpr watchdog timer prescaler register r250 fa 0 xxxxxxxx wdtcr watchdog timer control register r251 fb 0 00010010 wcr wait control register r252 fc 0 01111111 a.11. watchdog timer configuration/initialization mnem. name reg. hex pg. reset value (binary) spidr spi data register r253 fd 0 xxxxxxxx spicr spi control register r244 f4 0 00100000 a.12. spi initialization mnem. name reg. hex pg. reset value (binary) eecr eeprom control register r241 f1 0 00000000 a.13. eeprom initialization (st9040 only) ? initialization of the st9 21/44
. sbttl a st9030 registers addresses and contents o . include ac:\st9\bin\symbols.inco ; the reader should refer to the file containing the ; declaration of all the bits and registers of the st9030 ; for the symbols used in the following listing. ; ; .nlist ;***************************************************************** ;* this program demonstrates the configuration of st9 peripherals* ;***************************************************************** ;********************** ;*ram declaration* ;********************** prescal_t0 := r2 ; value of timer 0 prescaler val_capt_t0 := rr4 ; value of timer 0 capture register nb_event_t0 := rr4 ; number of timer 0 event lg_dma := rr6 ; length of dma cpt_ad_dma := rr8 ; dma address register cpt_lg_dma := rr8 ; dma counter register ad_conv := r3 ; conversion start address it_t0_level = 4 ; timer 0 priority level it_cad_level = 6 ; a/d converter priority level ;**************************** ;*interrupt vector addresses* ;**************************** core_it_vect := 00h ; core interrupt vectors t0_it_vect := 10h ; timer 0 interrupt vectors ext_it_vect := 20h ; external interrupt vectors adc_it_vect := 30h ; a/d converter interrupt vectors sci_it := 40h ; sci interrupt vector ;******************* ;*stack declaration* ;******************* sstack := 223 ; system stack address group d c ustack := 191 ; user stack address group b appendix b. examples of st9 peripheral configurations ? initialization of the st9 22/44
;******************** ;*group number names* ;******************** bk0 := 0 bk1 := 1 bk2 := 2 bk3 := 3 bk4 := 4 bk5 := 5 bk6 := 6 bk7 := 7 bk8 := 8 bk9 := 9 bka := 10 bkb := 11 bkc := 12 bkd := 13 bke := 14 bkf := 15 bk_0 := bk0 * 2 ; free user group bk_bdt:= bk2 * 2 ; twd group bk_cad:= bk5 * 2 ; a/d group bk_t0 := bk4 * 2 ; mftimer 0 group bk_sci:= bk6 * 2 ; sci group. bk_f := bkf * 2 ; paged registers appendix b. examples of st9 peripheral configurations (continued) ? initialization of the st9 23/44
;******************************************* ;*declaration of the interrupt vector table* ;******************************************* .text ; start of program .org core_it_vect ; core interrupt vector ********************** .word div0 ; divide by 0 interrupt vector .word top_level_it; top level interrupt vector .org t0_it_vect ; timer 0 interrupt vector ; *********************** .org t0_it_vect + 4 ; unused addresses .word t0_cap ; timer 0 capture interrupt vector .word t0_comp ; timer 0 compare interrupt vector .org ext_it_vect ; external interrupt vector ; ************************* wdt_it: .word tempo ; watchdog timer interrupt vector .org adc_it_vect ; adc interrupt vector ; ******************** .word reset_start ; analog watchdog interrupt vector .word adc_eoc ; end of conv. interrupt vector .org sci_it ; sci interrupt vector ; ******************** .org sci_it + 4 ; unused addresses .word rec_data ; receiver interrupt .word tra_hold ; transmitter interrupt appendix b. examples of st9 peripheral configurations (continued) ? initialization of the st9 24/44
;********************** ;*start of main module* ;********************** .org 100h ; start of code reset_start: ld moder,#11100000b ; clock mode register ; internal stack ; no prescaling ; external clock divided by 2 ld cicr,#10000111b ; central interrupt ; control register ; priority level = 7 ; concurrent mode ; disable interrupt clr flagr spp #wdt_pg ld wcr,#wden ; watch dog mode disabled, ; no wait states. ld eimr,#0 ; mask all channel interrupts. ; at reset,global counter enable ; bit is active. ld ssplr,#sstack + 1 ; load system stack pointer ld usplr,#ustack + 1 ; load user stack pointer call init_io ; init i/o ports main: jxt main ; include your main program here ! appendix b. examples of st9 peripheral configurations (continued) ? initialization of the st9 25/44
;************************************************************** ;*configuration of timer 0 i/o pins and a/d converter i/o pins* proc init_io [ppr] { ;............. ;............. p3.0 (t0ina) p3.2 (t0inb) input tristate ttl ;............. p3.1 (t0outa) p3.3 (t0outb) output alternate function push_pull ttl spp #p3c_pg ; port 3 control register page ld p3c0r,#00001111b ld p3c1r,#00001010b ld p3c2r,#00000101b ;............. end of init. p3 ;............. initialization of a/d convertor inputs ;............. p4.7 (ain7) alternate function open drain ttl ;............. p4.6 (ain6) alternate function open drain ttl spp #p4c_pg ; port 4 control register page ld p4c0r,#11000000b ld p4c1r,#11000000b ld p4c2r,#11000000b ;............ end of init. p4 ;............ initialization of sci i/o ; p70: input = sin. ; p71: af = sout. ; p72: af = txclck. ; p73: af = rxclck. spp #p7c_pg ; port 7 control page. ld p7c0r,#00001111b ; bit 0 (sin): in, tri, ttl. ld p7c1r,#11111110b ; bit 1,2,3 (sout, txck, rxck): af,pp,ttl. ld p7c2r,#00000001b ; others : out,pp,ttl. } appendix b. examples of st9 peripheral configurations (continued) ? initialization of the st9 26/44
;********************************************* ;*section code for the core interrupt routine* ;********************************************* ;eeeeeeeeeeeeeeeeee- ;*interrupt routine for zero division* ;eeeeeeeeeeeeeeeeee- div0: nop ret ;eeeeeeeeeeeeeeeeee ;*interrupt routine for top_level_it* ;eeeeeeeeeeeeeeeeee top_level_it: nop iret ;eeeeeeeeeeeeeeeeeeeee ;*interrupt routine for timer watchdog int* ;eeeeeeeeeeeeeeeeeeeee tempo: nop iret appendix b. examples of st9 peripheral configurations (continued) ? initialization of the st9 27/44
;*********************** ;*define timer 0 macros* ;*********************** .macrot0_start_it ; start timer 0, enable interrupts spp #t0d_pg ; select timer 0 data register page and t_tcr,#ccl ; counter clear bit or t_tcr,#cen ; counter enable bit or t_idmr,#gtien ; global interrupt mask .endm .macrot0_start_dma_cap ; start timer 0, enable interrupts ; and dma spp #t0d_pg ; select timer 0 data register page or t_idmr,#( gtien | cp0d ) ; global interrupt mask or t_tcr,#cen ; counter enable bit .endm .macrostop_t0 ; stop timer 0 spp #t0d_pg ; select timer 0 data register page and t_idmr,#gtien ; global interrupt mask and t_tcr,#cen ; counter enable bit .endm appendix c. examples of timer 0 configurations ? initialization of the st9 28/44
;************************************************************ proc gest_t0_itcapt{ ;configuration of timer 0 for it capture ;tcr: - stop count ; - clear on capture ; - up count ;tmr: - disable output ; - internal clock ; - disable bivalue mode ; - disable retrigger mode ; - disable reg1 mode ; - continuous mode ; - enable reg0 mode ;icr: - exta trigger ; - falling edge on exta ; - extb no operation ;oacr-obcr: - no operation ;idmr: - interrupt on capture reg0 ;dcpr: - reset value ;dapr: - 00h ;ivr: - interrupt vector 10h = t0_it_vect ;idcr: - level 4 spp #t0d_pg ; timer 0 data register page ld t_tcr,#01001000b ; tcr ld t_tmr,#00001010b ; tmr ld t_icr,#01010100b ; icr ld t_prsr,prescal_t0 ; prescaler ld t_oacr,#11111100b ; oacr ld t_obcr,#11111100b ; obcr ld t_flagr,#00h ; flagr ld t_idmr,#00100000b ; idmr spp #t0c_pg ; timer 0 control register page ld t0_dcpr,#00h ; dcpr ld t0_dapr,#0 ; dapr ld t0_ivr,#t0_it_vect ; ivr interrupt vector 14h ld t0_idcr,#it_t0_level ; priority level 4 t0_start_it ; start timer 0, enable interrupt } appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 29/44
;********************************************************************* proc gest_t0_event{ ; configuration of timer 0 into event counter mode ; it compare is serviced when nb_event_t0 is reached ;tcr: - stop count ; - up count ; - clear on compare ;tmr: - disable output 0-1 ; - no bivalue mode ; - no bicapture ; - internal clock ; - disable retrigger mode ; - continuous mode ;icr: - extb ext.clock ; - falling edge on extb ; - exta i/o ;oacr-obcr: - no operation ;flag: - reset value ;idmr: - it compare 0 ;dcpr: - 00h ;dapr: - 00h ;ivr: - interrupt vector 10h = t0_it_vect ;idcr: - priority level 4 ;comp0 spp #t0d_pg ; timer 0 data register page ldw t_cmp0r,nb_event_t0 ; comp0 ld t_tcr,#00111000b ; tcr ld t_tmr,#00000010b ; tmr ld t_icr,#01000010b ; icr ld t_prsr,prescal_t0 ; prescaler ld t_oacr,#11111100b ; oacr ld t_obcr,#11111100b ; obcr ld t_idmr,#00000100b ; idmr appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 30/44
spp #t0c_pg ; timer 0 control register page ld t0_dcpr,#0 ; dcpr ld t0_dapr,#0 ; dapr ld t0_ivr,#t0_it_vect ; ivr ld t0_idcr,#it_t0_level ; idcr t0_start_it } ;********************************************************************* proc gest_t0_dma{ ;configuration of timer0 in it capture associated to the dma mode ;the length of dma is given by lg_dma ;tcr: - stop count ; - no clear ; - up count ;tmr: - disable interrupt ; - no bivalue mode ; - no capture ; - external/internal clock ; - disable retrigger mode ; - continuous count ;icr: - exta trigger ; - falling edge on exta ; - exta no operation ;oacr-obcr: - no operation ;idmr: - no interrupt, dma / capture reg0 ;dcpr: - dma ext. data/program memory - dma counter ;dapr: - dma external program memory - dma address ;ivr: - interrupt vector 10h = t0_it_vect ;idcr: - interrupt dma priority level 4 spp #t0d_pg ; select timer 0 data register ld t_tcr,#01001000b ; tcr ld t_tmr,#00001010b ; tmr ld t_icr,#01010100b ; icr ld t_prsr,prescal_t0 ; prescaler ld t_oacr,#11111100b ; oacr ld t_obcr,#11111100b ; obcr appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 31/44
ld t_flagr,#00h ; flagr ld t_idmr,#00100000b ; idmr spp #t0c_pg ; select timer 0 control register ld t0_dcpr,#cpt_lg_dma ; dcpr lg. dma = 4ch = rr12 ;=rr76 ld t0_dapr,#cpt_ad_dma ; dapr ad. dma = 48h = rr8 ;=rr72 ld t0_ivr,#t0_it_vect ; ivr ld t0_idcr,#it_t0_level ; priority level 4 ldw cpt_lg_dma,lg_dma ; init dma counter ldw cpt_ad_dma,#0ff00h ; dma address in rom is 0ff00h t0_start_dma_cap ; enable interrupt. and dma } ;******************************************************************** ; example for timer 0 and timer 1 in parallel mode ; a toggle is generated on t0outb and t1outb on each overflow ;******************************************************************** ;****************** ;initialize timer 0 ;****************** timer0:: spp #t0d_pg ; select timer 0 register page srp #bk_f ; select working register ld t_tcr,#00011000b ; counter clear ; software up ld t_tmr,#10001000b ; enable output 1 ; disable output 0 ; not bivalue mode ; reg 1 monitor counter value ; reg 0 capture ; internal clock ; retrigger mode ; continuous mode appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 32/44
ld t_icr,#00 ; no action on input pins ld t_prsr,#00 ; no prescaling ld t_oacr,#11111100b ; no action on output0 ld t_obcr,#11110100b ; toggle on ovf ld t_flagr,#00 ld t_idmr,#00 .macrot0_start ; start timer 0 spp #t0d_pg ; select timer 0 data register page or t_tcr,#cen ; counter enable bit .endm ;****************** ;initialize timer 1 ;****************** timer1:: spp #t1d_pg ; select timer 1 register page srp #bk_f ; select working register ld t_tcr,#00011000b ; counter clear ; software up ld t_tmr,#10001100b ; enable output 1 ; disable output 0 ; not bivalue mode ; reg 1 monitor counter value ; reg 0 capture ; parallel mode ; retrigger mode ; continuous mode ld t_icr,#00 ; no action on input pins ld t_prsr,#00 ; no prescaling ld t_oacr,#11111100b ; no action on t1outa ld t_obcr,#11110100b ; toggle on ovf t1outb ld t_flagr,#00 ld t_idmr,#00 appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 33/44
.macrot1_start ; start timer 1 spp #t1d_pg ; select timer 1 data register page and t_tcr,#ccl ; counter clear bit or t_tcr,#cen ; counter enable bit .endm or cicr,#10000000b ; global counter enable loop { } ;********************************************************************* ; interrupt subroutines for timer 0 ;********************************************************************* ;these subroutines are serviced on timer 0 interrupts. they come from: ; t0_it_vect + 4 for both - it/capture ; and - dma it/capture end of block ; t0_it_vect + 6 for - it/compare ;*********************************************************************** ; timer 0 capture interrupt subroutine: ; - it capture on event on exta ; - dma it/capture end of block t0_cap: spp #t0d_pg ; timer 0 data register page tm t_flagr,#ccp0 ; mask successful capture jxz reset_start ; this is not an it capture ;==pb tm t_flagr,#ocp0 ; overrun on capture 0 ? jxnz reset_start ; yes == reset and t_flagr,#~cp0 ; reset successful capture flags and t_flagr,#~ocp0 ; reset overrun on capture 0 flag iret ; return from interrupt appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 34/44
;************************************************************************ ;timer 0 compare interrupt subroutine: ; - it/compare t0_comp: spp #t0d_pg ; timer 0 data register page tm t_flagr,#cm0 ; mask successful compare jxz reset_start ; reset if it is not ; an it compare tm t_flagr,#ocm0 ; overrun on compare 0 ? jxnz reset_start ; yes == reset and t_flagr,#~cm0 ; reset successful compare bit and t_flagr,#~ocm0 ; reset overrun compare 0 bit iret ; return from interrupt ;******** end of timer 0 configuration examples ************ appendix c. examples of timer 0 configurations (continued) ? initialization of the st9 35/44
;********************************************************************* proc sg_conv{ ; a/d converter is configured as follows: ; - one shot conversion ; - power up mode ; - it upon end of conversion ; - start mode ; - autoscan from channel number ad_conv ; - no int upon analog compare spp #ad0_pg ; a/d converter register page ld ad_clr,#00000100b ; control logic register ; power up ; stop ; single mode ; channel 0 ld ad_crr,#00h ; compare result register ld ad_icr,#00100000b ; interrupt control register ; mask analog watchdog ; enable end of conversion or ad_icr,#it_cad_level ; priority level = 6 ld ad_ivr,#adc_it_vect ; interrupt vector register ld r0,ad_conv ; ad_conv = channel number swap r0 rcf rlc r0 ; mask for channel number or ad_clr,r0 ; start conversion address ld r10, #40 loop [r10] { ; wait 60 m s before start the first ; conversion nop } or ad_clr,#st ; start conversion } appendix d. examples of a/d convertor configurations ? initialization of the st9 36/44
;************************************************************* ; a/d end of conversion interrupt subroutine adc_eoc: spp #ad0_pg ; a/d converter register page ; converter flags and ad_icr,#~(ecv | awd) ; end of conversion pending flag ; analog watch_dog pending flag and ad_clr,#~(st | pow ) ; stop converter ; power down mode iret appendix d. examples of a/d convertor configurations (continued) ? initialization of the st9 37/44
;*********************** ; sci ;constant declarations. ;*********************** priority_sci = 4 ; sci priority level div_9600 = 78 ; brg divisor for a 9600 baud clock ; with a 12 mhz system clock. div_4800 = 156 ; to generate a 4800 bds clock. div_2400 = 312 ; to generate a 2400 bds clock. div_1200 = 614 ; to generate a 1200 bds clock. vc_9600 := 4 ; character for 9600 bauds. return = 00dh lng_dma_sci := 0fh ; dma length. depart_dma_sci := 0a0h ; start dma address . ; bk_dma_sci reserved for this. num_tdap := 6 ; contains dma transmit address pointer value. num_tdcp := 7 ; contains dma transmit address counter value. data := r2 ; data hold register rec_ptr := rr6 rec_cpt := rr8 ;******************************************************************** ; function: ; - i/o ports initialization. ; - speed and frame initialization. ; - compare register initialization. ; - interrupt and dma configuration. ; ; interrupt request: ; - receive error. ; - receiver data. ; - end of dma transmit. ; ; inputs: none ; ; outputs:none ; appendix e. examples of sci configurations ? initialization of the st9 38/44
;********************************************************************* proc init_sci { ;e- communication format configuration. ; ; communication format is configured as follows: ; ; - 8 data bit transmitted or received character. ; - 1 stop bit included in data format. ; - parity even. ; - 9600 baud communication rate. ;e- sci configuration. ; ; - no address bit included between the parity bit and the stop bit. ; - address mode: address interrupt if character match. ; - dma permits transmission from eeprom memory to serial line. ; - receiver data interrupt unmask (to detect a received data item). ; - transmitter data interrupt unmask (to detect dma end of block). ; - receiver error interrupt unmask (to detect overrun, parity or framing error). spp #sci1_pg ; sci register page. srp #bk_f ; to address sci registers with r. ld s_brglr,#00 ; reset sci ld s_chcr,#( wl8 | sb10 | pen | ep | am ) ; 8 data bit. ; 1 stop bit. ; parity even. ; no address bit. ; ame = 0, am = 1. ; = it if character match. ld s_ccr,#txclk ; xmit clock source = brg. ; receiver clock source = brg. ; 16x asynchronous mode. ld s_acr,#return ; end of command acquisition. appendix e. examples of sci configurations ( continued) ? initialization of the st9 39/44
;e- interrupt and dma configuration. ld s_ivr,#sci_it ; interrupt vector register. ld s_tdcpr,#num_tdcp ; tx dma counter in register file. ld s_imr,#( rxdi | rxa | rxe ) ; mask transmitter data interrupt. ; unmask receiver data interrupt. ; unmask receiver data error interrupt. ; unmask receiver address interrupt. ; reset of the pending bits. ld s_idpr,#priority_sci ; mask transmitter dma request. ; sci exeptions priority level. ld s_brglr,#div_9600 ; brg divisor for 9600 bauds, start sci ; !!! with a 24 mhz external clock, ; !!! or 4800 bds (12 mhz external clock.) } ;e- end of proc. ;********************************************************************* ; sync_com: proc sync_com { spp #sci1_pg srp #bk_f ld r#num_tdap,#(depart_dma_sci) ; dma pointer initialisation. ld r#num_tdcp,#(lng_dma_sci) ; dma counter initialisation. or s_idpr,#txd ; unmask transmitter dma request. ; unmask transmitter data interrupt. ld s_imr,#txdi ; unmask transmitter data interrupt. ; mask receiver data interrupt. ; mask receiver data error interrupt. } ;e- end of proc. appendix e. examples of sci configurations (continued) ? initialization of the st9 40/44
********************************************************************* ; rec_data: receive interrupt. rec_data: pushu ppr ; save page pointer. pushuw rpp ; save register pointer pair. spp #sci1_pg ; sci register page. srp #bk_sci ; 16 registers reserved for sci. ld data,s_rxbr ; read the data received. and data,#07fh ; mask the parity bit. ld rec_ptr(rec_cpt),data ; storage of the received data. incw rec_cpt cpw rec_cpt,#7 ; end of the table. and s_isr,#~rxdp ; reset receiver data pending flag. popuw rpp ; restore register pointer pair popu ppr ; restore page pointer iret appendix e. examples of sci configurations (continued) ? initialization of the st9 41/44
;************************************************************************* ; tra_hold: end of dma transmitter interrupt ; function: ; - check interrupt source. ; - disable dma mask . ; - enable receiver interrupt mask. tra_hold: pushu ppr ; save page pointer. pushuw rpp ; save register pointer pair. spp #sci1_pg ; sci register page. srp #bk_f ; to address sci registers with r. tm s_imr,#txeob if [setz] { ; if a transmitter end of block interrupt. bres s_txeob ; dis. tr ansmit end of block pending bit. bres s_txhem ; reset transmit holding reg. empty . ld s_imr,#~( rxdi | rxe) ; unmask receiver data interrupt. ; unmask receiver data error interrupt. ; mask transmitter data interrupt. }else{ jx reset_start ; if not a normal interrupt source. } ;e- end of if. popuw rpp ; restore register pointer pair popu ppr ; restore page pointer iret appendix e. examples of sci configurations (continued) ? initialization of the st9 42/44
;********************************************************************* ;init_wdt: this procedure initializes and starts watchdog timer. ; ; watchdog mode is disabled. ; timer will down count in continuous mode. ; it will generate an interrupt on channel a0 at each end of count. ; e- see the external interrupt parameters initialization. ;********************************************************************* proc init_wdt { spp #wdt_pg ; to access in paged registers with r. ld wcr,#wden ; watch dog mode dis., no wait states. clr wdtpr ; 333 ns(sys.clock=12 mhz) min. count, ; prescaler = 0. ldw wdtr,#3003 ; (3003 x 333) ns = 1 ms. or wdtcr,#stsp ; timer starts down counting. ; continuous mode. ; watch dog disabled. ; input section disabled. ; output disabled. ; interrupt a0 on timer eoc. ; top level interrupt on sw trap. };e- end of proc. ;**************************************** ;*interrupt on channel a0 initialization* ;**************************************** spp #wdt_pg srp #bk_f ; page 0 reg. direct addressing mode. clr eipr ; dis. all external int. pending bits. nop ; see warning (tech. manual-chap. 8). ld eivr,#ext_it_vect ; external interrupt vector. ; iaos - tlis = 00 = ... ; ... a0 int. will be on wdt end of count. ld eiplr,#0feh ; priority level: group inta0,inta1 = 4,5. ld eimr,#ia0sm ; unmask interrupt a0 channel ; (wdt end of count). appendix f. examples of watchdog timer configurations ? initialization of the st9 43/44
information furnished is believed to be accurate and reliable. however, sgs-thomson microelectronics assumes no responsability for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of sgs-thomson microelectronics. specifications mentioned in this publication are subject to change without notice. this publication supersedes and replaces all information previously supplied. sgs-thomson microelectronics products are not authorized for use as critical components in life support devices or systems without the express written approval of sgs-thomson microelectronics. ? 1994 sgs-thomson microelectronics - all rights reserved. purchase of i 2 c components by sgs-thomson microelectronics conveys a license under the philips i 2 c patent. rights to use these components in an i 2 c system is granted provided that the system conforms to the i 2 c standard specification as defined by philips. sgs-thomson microelectronics group of companies australia - brazil - france - germany - hong kong - italy - japan - korea - malaysia - malta - morocco - the netherlands singapore - spain - sweden - switzerland - taiwan - thailand - united kingdom - u.s.a. the software included in this note is for guidance only. sgs-thomson shall not be held liable for any direct, indirect or consequential damages with respect to any claims arising from use of the software. ? initialization of the st9 44/44


▲Up To Search▲   

 
Price & Availability of AN413

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X